-- Copyright (c) 2025 Huawei Technologies Co., Ltd.
-- openUBMC is licensed under Mulan PSL v2.
-- You can use this software according to the terms and conditions of the Mulan PSL v2.
-- You may obtain a copy of Mulan PSL v2 at: http://license.coscl.org.cn/MulanPSL2
-- THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
-- EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
-- MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
-- See the Mulan PSL v2 for more details.

local mc_utils = require 'mc.utils'

local test_prepare_data = {}

function test_prepare_data.prepare_mds_test_data(test_data_dir)
    local dir_list = {
        "sr", "data/sr"
    }
    for _, dir in pairs(dir_list) do
        os.execute("mkdir -p " .. test_data_dir .. "/" .. dir)
    end
end

function test_prepare_data.prepare_persistence_data(test_data_dir)
end

function test_prepare_data.prepare_test_data(test_data_dir)
end

function test_prepare_data.setup(test_data_dir)
    assert(os.execute("mkdir -p " .. test_data_dir) == true)
    test_prepare_data.prepare_test_data(test_data_dir)
    test_prepare_data.prepare_mds_test_data(test_data_dir)
    test_prepare_data.prepare_persistence_data(test_data_dir)

    local temp_dir = os.getenv("PROJECT_DIR") .. "/temp"
    -- 防止部分接口未拉起时，访问耗时过长（不影响测试），将重试次数修改为1次
    local ret = os.execute(string.format("find %s -name client.lua|xargs sed -i -e 's/local MAX_RETRY_TIMES<const> =" ..
        " 10/local MAX_RETRY_TIMES<const> = 1/g'", temp_dir))
    assert(ret == true)
    -- 部分组件未被拉起，防止maca重启所有服务，将MAX_ABNORMAL_RESET_TIMES设置为一个超大值
    ret = os.execute(string.format("sed -i -e 's/local MAX_ABNORMAL_RESET_TIMES<const> ="..
        " 10/local MAX_ABNORMAL_RESET_TIMES<const> = 0/g' %s/opt/bmc/apps/maca/lualib" ..
            "/app_mgmt/monitor/startup/init.lua", temp_dir))
    assert(ret == true)
end

return test_prepare_data